﻿define([],
function () {
    'use strict';

    return {

        // Finds the position of first item in the array matched by fn
        indexOf: function (array, fn, fromIndex) {
            var i,
                pivot = (fromIndex) ? fromIndex : 0,
                length = array.length;

            if (length === 0 || pivot >= length) {

                return -1;
            }

            if (pivot < 0) {

                pivot = length - Math.abs(pivot);
            }

            for (i = pivot; i < length; ++i) {

                if (fn(array[i])) {

                    return i;
                }
            }

            return -1;
        },

        // Removes the element matched by fn
        remove: function (array, fn, fromIndex) {
            var i = this.indexOf(array, fn, fromIndex);

            if (i > -1) {

                array.splice(i, 1);

                return true;
            }

            return false;
        }

    };
});